package com.etrans.web.gps.business.gis.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.etrans.web.gps.base.controller.BaseController;
import com.etrans.web.gps.business.gis.domain.Location;
import com.etrans.web.gps.business.gis.domain.TrackExpand;
import com.etrans.web.gps.business.gis.service.LocationService;
import com.etrans.web.gps.business.system.domain.SysUser;

@Controller
@RequestMapping("/gis/location/*")
public class LocationAnalyser extends BaseController {


	@Autowired
	private LocationService locationService;

	
	@ResponseBody
	@RequestMapping("Analyser.html")
	public ModelAndView location() {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("views/business/gis/locationAnalyser");
		return mav;
	}

	/**
	 * 取车辆定位数据
	 * 
	 * @param tradeId
	 *            行业ID
	 * @param status
	 *            车辆状态 3：超速 1：疲劳 2：停车
	 * @return
	 */
	@ResponseBody
	@RequestMapping("position.html")
	public List<Location> getPosition(int tradeId, int status) {
		List<TrackExpand> result = new ArrayList<>();
		Map<String, Object> param = new HashMap<>();
		param.put("trade", tradeId);
		SysUser user = getSysUser();
		if (!user.isSuper_admin()) {
			param.put("isSuperAdmin", String.format("%08d", user.getArea_id()));
		}
		List<String> vehicleList;
		try {
			// 查询车辆key=车牌号：车牌颜色ID
			vehicleList = locationService.queryVehicleKeys(param);
			List<Location> location = locationService.getLocation(vehicleList, status);
			return location;
		} catch (Exception e) {
			e.printStackTrace();
		}

		return null;
	}
	
	@ResponseBody
	@RequestMapping("getVehicleInfo.html")
	public Map<String, Object> getVehicleInfo() {
		HashMap<String, Object> param = new HashMap<>();
		Map<String, Object> result = new HashMap<>();
		SysUser user = getSysUser();
		try {
			param.put("FullID", String.format("%08d", user.getArea_id()));
			// 查询车辆信息
			List<HashMap<String, Object>> vehicleList = locationService.queryVeListByRole(param);
			result.put("code", 10001);
			result.put("data", vehicleList);
			return result;
		} catch (Exception e) {
			e.printStackTrace();
			result.put("code", 10002);
			return result;
		}

		
	}
}
